/*
 * Copyright 2018-present KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.nsgf.library.domain.request;

import androidx.annotation.NonNull;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.kunminx.architecture.domain.message.MutableResult;
import com.kunminx.architecture.domain.message.Result;
import com.nsgf.library.data.api.AccountService;
import com.nsgf.library.data.bean.AddressBean;
import com.nsgf.library.data.bean.BusinessBean;
import com.nsgf.library.data.bean.BusinessSettleTypeBean;
import com.nsgf.library.data.bean.Category;
import com.nsgf.library.data.bean.ClockInBean;
import com.nsgf.library.data.bean.ConfirmOrderBean;
import com.nsgf.library.data.bean.LibraryInfo;
import com.nsgf.library.data.bean.MessageBean;
import com.nsgf.library.data.bean.OrderDetailBean;
import com.nsgf.library.data.bean.OrderListBean;
import com.nsgf.library.data.bean.PointListBean;
import com.nsgf.library.data.bean.ProductBean;
import com.nsgf.library.data.bean.ProductDetailBean;
import com.nsgf.library.data.bean.Shop;
import com.nsgf.library.data.bean.UserDataBean;
import com.nsgf.library.data.bean.XBannerBeanInfo;
import com.nsgf.library.data.repository.DataRepository;
import com.nsgf.library.data.response.DataResult;
import com.nsgf.library.data.response.ResponseStatus;
import com.nsgf.library.utils.ToastUtils;

import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
 * 用户账户 Request
 * <p>
 * TODO tip 1：让 UI 和业务分离，让数据总是从生产者流向消费者
 * <p>
 * UI逻辑和业务逻辑，本质区别在于，前者是数据的消费者，后者是数据的生产者，
 * "领域层组件" 作为数据的生产者，职责应仅限于 "请求调度 和 结果分发"，
 * <p>
 * 换言之，"领域层组件" 中应当只关注数据的生成，而不关注数据的使用，
 * 改变 UI 状态的逻辑代码，只应在表现层页面中编写、在 Observer 回调中响应数据的变化，
 * 将来升级到 Jetpack Compose 更是如此，
 * <p>
 * Activity {
 * onCreate(){
 * vm.livedata.observe { result->
 * panel.visible(result.show ? VISIBLE : GONE)
 * tvTitle.setText(result.title)
 * tvContent.setText(result.content)
 * }
 * }
 * Create by GC at 24/10/26
 */
public class AccountRequester extends Requester implements DefaultLifecycleObserver {

    //TODO tip 3：👆👆👆 让 accountRequest 可观察页面生命周期，
    // 从而在页面即将退出、且登录请求由于网络延迟尚未完成时，
    // 及时通知数据层取消本次请求，以避免资源浪费和一系列不可预期问题。

    private final MutableResult<ResponseStatus<UserDataBean>> userDataResult = new MutableResult<>();
    private final MutableResult<DataResult<ResponseStatus<String>>> src = new MutableResult<>();
    private final MutableResult<DataResult<ClockInBean>> statisticsResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<UserDataBean>> userResultProject = new MutableResult<>();

    private final MutableResult<ResponseStatus<String>> srcSuccess = new MutableResult<>();

    private final MutableResult<ResponseStatus<LibraryInfo>> libraryInfo = new MutableResult<>();
    private final MutableResult<ResponseStatus<LibraryInfo>> signSummaryResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<LibraryInfo>>> rainRecordList = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<LibraryInfo>>> libraryList = new MutableResult<>();
    private final MutableResult<ResponseStatus<Object>> stringResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<ProductBean>>> productBeanResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<ProductBean>>> bannerResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<ProductBean>> productResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<ProductBean>> queryDiscountedProductsResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<BusinessBean>>> businessResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<ProductDetailBean>> productDetailResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<Category>>> categoryResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<Shop>> shopResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<ConfirmOrderBean>> conformOrderResult = new MutableResult<>();

    private final MutableResult<ResponseStatus<List<AddressBean>>> addressListResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<AddressBean>> addressResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<List<ConfirmOrderBean.CouponsDTO>>> couponList = new MutableResult<>();

    private final MutableResult<ResponseStatus<Object>> signVideoResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<BusinessBean>> businessProductResult = new MutableResult<>();

    private final MutableResult<ResponseStatus<OrderListBean>> orderListResult = new MutableResult<>();

    private final MutableResult<ResponseStatus<OrderDetailBean>> orderDetailResult = new MutableResult<>();
    private final MutableResult<ResponseStatus<PointListBean>> pointBeanResult = new MutableResult<>();

    private final MutableResult<ResponseStatus<List<MessageBean.DataBean>>> messageListResult = new MutableResult<>();

    private final MutableResult<ResponseStatus<List<BusinessSettleTypeBean>>> businessSettleTypeResult = new MutableResult<>();

    private final MutableResult<ResponseStatus<List<XBannerBeanInfo>>> bannerListResult = new MutableResult<>();

    public MutableResult<ResponseStatus<UserDataBean>> getUserResultProject() {
        return userResultProject;
    }

    //TODO tip 4：应顺应 "响应式编程"，做好 "单向数据流" 开发，
    // MutableResult 应仅限 "鉴权中心" 内部使用，且只暴露 immutable Result 给 UI 层，
    // 通过 "读写分离" 实现数据从 "领域层" 到 "表现层" 的单向流动，


    public Result<DataResult<ResponseStatus<String>>> getSrc() {
        return src;
    }


    //TODO tip 5：模拟可取消的登录请求：
    //
    // 配合可观察页面生命周期的 accountRequest，
    // 从而在页面即将退出、且登录请求由于网络延迟尚未完成时，
    // 及时通知数据层取消本次请求，以避免资源浪费和一系列不可预期的问题。

    public Disposable mDisposable;

    //TODO tip 6: requester 作为数据的生产者，职责应仅限于 "请求调度 和 结果分发"，
    //
    // 换言之，此处只关注数据的生成和回推，不关注数据的使用，
    // 改变 UI 状态的逻辑代码，只应在表现层页面中编写，例如 Jetpack Compose 的使用，

    // 获取到请求类型（MediaType）
    private static MediaType mediaType = MediaType.parse("application/json;charset=UTF-8");


    /**
     * 版本更新
     */
    public void getVersion() {

        Observable observable = DataRepository.getRetrofitNotTokenInstance().create(AccountService.class).getVersion();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<LibraryInfo>>(new HttpOnNextListener<ResponseStatus<Object>>() {
            @Override
            public void onSuccess(ResponseStatus<Object> dataResult) {
                stringResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                stringResult.postValue(new ResponseStatus<>(0, true, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);
    }


    public void getNewLoginInfo() {

        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<UserDataBean>>(new HttpOnNextListener<ResponseStatus<UserDataBean>>() {
            @Override
            public void onSuccess(ResponseStatus<UserDataBean> dataResult) {

                if (0 == dataResult.getResponseCode()) {
                    userResultProject.postValue(dataResult);
                } else {
                    userResultProject.postValue(new ResponseStatus<>(1, true, dataResult.getMsg()));
                    ToastUtils.showShortToast(dataResult.getMsg());
                }
            }

            @Override
            public void onFail(String e) {
                userResultProject.postValue(new ResponseStatus<>(1, true, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getNewLoginInfo();
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void queryYouXuanList(int page, int position) {
        Observable observable = null;
        if (position == 0) {
            observable =
                    DataRepository.getRetrofitInstance().create(AccountService.class)
                            .getZhanXuanList(page, 10);
        } else if (position == 1) {

            observable =
                    DataRepository.getRetrofitInstance().create(AccountService.class)
                            .queryYouXuanList(page, 10);
        } else if (position == 2) {

            observable =
                    DataRepository.getRetrofitInstance().create(AccountService.class)
                            .getYunDianList(page, 10);
        } else if (position == 3) {

            observable =
                    DataRepository.getRetrofitInstance().create(AccountService.class)
                            .getTeGongList(page, 10);
        }

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<ProductBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<ProductBean>> dataResult) {

                productBeanResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                productBeanResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getProductList(int page, String keyword) {
        Observable observable =
                DataRepository.getRetrofitInstance().create(AccountService.class)
                        .getProductList(keyword, page, 10);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<ProductBean>>() {
            @Override
            public void onSuccess(ResponseStatus<ProductBean> dataResult) {

                productResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                productResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void queryDiscountedProducts(int size) {

        JsonObject params = new JsonObject();
        params.addProperty("pageNo", "1");
        params.addProperty("pageSize", size);
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .queryDiscountedProducts(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<ProductBean>>() {
            @Override
            public void onSuccess(ResponseStatus<ProductBean> dataResult) {

                queryDiscountedProductsResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                queryDiscountedProductsResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void queryHotSales() {

        JsonObject params = new JsonObject();
        params.addProperty("pageNo", "1");
        params.addProperty("pageSize", "2");
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .queryHotSales(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<ProductBean>>() {
            @Override
            public void onSuccess(ResponseStatus<ProductBean> dataResult) {

                productResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                productResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getSpuList() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getSpuList();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<ProductBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<ProductBean>> dataResult) {

                productBeanResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                productBeanResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void queryDirectStoreOrQueryFranchiseStore(int type) {
        Observable observable = null;
        if (type == 0)
            observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                    .queryDirectStore();
        else
            observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                    .queryFranchiseStore();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<BusinessBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<BusinessBean>> dataResult) {

                businessResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                businessResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<List<BusinessBean>>> getBusinessResult() {
        return businessResult;
    }

    public void getLunBoList() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getLunBoList();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<ProductBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<ProductBean>> dataResult) {

                bannerResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                bannerResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<List<ProductBean>>> getBannerResult() {
        return bannerResult;
    }

    public void productDetails(String id) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .productDetails(id);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<ProductDetailBean>>() {
            @Override
            public void onSuccess(ResponseStatus<ProductDetailBean> dataResult) {

                productDetailResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                productDetailResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void getAllProducts() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getAllProducts();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<Category>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<Category>> dataResult) {

                categoryResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                categoryResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<List<Category>>> getCategoryResult() {
        return categoryResult;
    }


    /**
     * 发送验证码
     *
     * @param phone 手机号
     * @param scene 发送场景
     */
    public void sendCode(String phone, int scene) {

        JsonObject params = new JsonObject();
        params.addProperty("mobile", phone);
        params.addProperty("scene", scene);
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .sendCode(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<ProductBean>>() {
            @Override
            public void onSuccess(ResponseStatus<ProductBean> dataResult) {

                productResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                productResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 登录
     *
     * @param phone
     * @param scene
     */
    public void loginCode(String phone, String scene) {

        JsonObject params = new JsonObject();
        params.addProperty("mobile", phone);
        params.addProperty("code", scene);
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .loginCode(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<UserDataBean>>() {
            @Override
            public void onSuccess(ResponseStatus<UserDataBean> dataResult) {

                userDataResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                userDataResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void businessLogin(String userName, String phone, String password) {

        JsonObject params = new JsonObject();
        params.addProperty("tenantName", userName);
        params.addProperty("userName", phone);
        params.addProperty("password", password);
        params.addProperty("checked", true);
        params.addProperty("isMerchant", 1);
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                .businessLogin(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<UserDataBean>>() {
            @Override
            public void onSuccess(ResponseStatus<UserDataBean> dataResult) {

                userDataResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                userDataResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void cartAdd(String skuId, int count) {

        JsonObject params = new JsonObject();
        params.addProperty("skuId", skuId);
        params.addProperty("count", count);
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .cartAdd(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                srcSuccess.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getCartList() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .cartList();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<Shop>>() {
            @Override
            public void onSuccess(ResponseStatus<Shop> dataResult) {

                shopResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                shopResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<Shop>> getShopResult() {
        return shopResult;
    }


    public void cartUpdateCount(String skuId, int count) {

        JsonObject params = new JsonObject();
        params.addProperty("id", skuId);
        params.addProperty("count", count);
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .cartUpdateCount(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                srcSuccess.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getSignInList() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getSignInList();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                libraryList.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                libraryList.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getSignInRecords() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getSignInRecords();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                rainRecordList.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                rainRecordList.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void queryUserPoint() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .queryUserPoint();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<LibraryInfo>>() {
            @Override
            public void onSuccess(ResponseStatus<LibraryInfo> dataResult) {

                libraryInfo.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                libraryInfo.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getSignSummary() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getSignSummary();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<LibraryInfo>>() {
            @Override
            public void onSuccess(ResponseStatus<LibraryInfo> dataResult) {

                signSummaryResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                signSummaryResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<LibraryInfo>> getSignSummaryResult() {
        return signSummaryResult;
    }


    public void createSignIn() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .createSignIn();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<Object>>() {
            @Override
            public void onSuccess(ResponseStatus<Object> dataResult) {

                stringResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void getSettlement(JsonObject params) {

        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .settlement(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<ConfirmOrderBean>>() {
            @Override
            public void onSuccess(ResponseStatus<ConfirmOrderBean> dataResult) {

                conformOrderResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                conformOrderResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void getAddressList() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getAddressList();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<AddressBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<AddressBean>> dataResult) {

                addressListResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                addressListResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getInviterList() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getInviterList();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<AddressBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<AddressBean>> dataResult) {

                addressListResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                addressListResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<List<AddressBean>>> getAddressListResult() {
        return addressListResult;
    }


    public void createAddress(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .createAddress(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                srcSuccess.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<ConfirmOrderBean>> getConformOrderResult() {
        return conformOrderResult;
    }


    public void modifyAddress(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .modifyAddress(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                srcSuccess.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void deleteAddress(String id) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .deleteAddress(id);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                srcSuccess.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void getDefaultAddress() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getDefaultAddress();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<AddressBean>>() {
            @Override
            public void onSuccess(ResponseStatus<AddressBean> dataResult) {

                addressResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                addressResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getAddress(String id) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getAddress(id);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<AddressBean>>() {
            @Override
            public void onSuccess(ResponseStatus<AddressBean> dataResult) {

                addressResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                addressResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<AddressBean>> getAddressResult() {
        return addressResult;
    }


    public void queryCoupons() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .queryCoupons();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<ConfirmOrderBean.CouponsDTO>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<ConfirmOrderBean.CouponsDTO>> dataResult) {

                couponList.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                couponList.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getSignVideo() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getSignVideo();

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<LibraryInfo>>() {
            @Override
            public void onSuccess(ResponseStatus<LibraryInfo> dataResult) {

                libraryInfo.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                libraryInfo.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<Object>> getSignVideoResult() {
        return signVideoResult;
    }


    public void queryTenantDetail(String id) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .queryTenantDetail(id);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<BusinessBean>>() {
            @Override
            public void onSuccess(ResponseStatus<BusinessBean> dataResult) {

                businessProductResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                businessProductResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<BusinessBean>> getBusinessProductResult() {
        return businessProductResult;
    }

    public MutableResult<ResponseStatus<List<ConfirmOrderBean.CouponsDTO>>> getCouponList() {
        return couponList;
    }


    /**
     * 查询我的订单
     *
     * @param page
     */
    public void getOrderList(int page, String type) {
        Observable observable =
                DataRepository.getRetrofitInstance().create(AccountService.class)
                        .getOrderList(page, 10, type);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<OrderListBean>>() {
            @Override
            public void onSuccess(ResponseStatus<OrderListBean> dataResult) {

                orderListResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                orderListResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getBusinessOrderList(int page, String type) {
        Observable observable =
                DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                        .getOrderList(page, 10, type);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<OrderListBean>>() {
            @Override
            public void onSuccess(ResponseStatus<OrderListBean> dataResult) {

                orderListResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                orderListResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<OrderListBean>> getOrderListResult() {
        return orderListResult;
    }

    public void deleteOrder(String id) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .deleteOrder(id);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                srcSuccess.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void cancelOrder(String id) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .cancelOrder(id);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                srcSuccess.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void createOrder(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .createOrder(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<LibraryInfo>>() {
            @Override
            public void onSuccess(ResponseStatus<LibraryInfo> dataResult) {

                libraryInfo.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                libraryInfo.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getOrderDetails(String id) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getOrderDetails(id);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<OrderDetailBean>>() {
            @Override
            public void onSuccess(ResponseStatus<OrderDetailBean> dataResult) {

                orderDetailResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                orderDetailResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<OrderDetailBean>> getOrderDetailResult() {
        return orderDetailResult;
    }


    public void setUpdatePayStatus(String id) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .setUpdatePayStatus(id);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                srcSuccess.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void refundOrder(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .refundOrder(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<String>>() {
            @Override
            public void onSuccess(ResponseStatus<String> dataResult) {

                srcSuccess.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                srcSuccess.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getPointsBenefit(int page, int type) {
        JsonObject params = getJsonObject(page, type);
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getPointsBenefit(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<PointListBean>>() {
            @Override
            public void onSuccess(ResponseStatus<PointListBean> dataResult) {

                pointBeanResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                pointBeanResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getAdminPointsBenefit(int page, int type) {
        JsonObject params = getJsonObject(page, type);
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                .getPointsBenefit(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<PointListBean>>() {
            @Override
            public void onSuccess(ResponseStatus<PointListBean> dataResult) {

                pointBeanResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                pointBeanResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    @NonNull
    private static JsonObject getJsonObject(int page, int type) {
        JsonObject params = new JsonObject();
        params.addProperty("pageNo", page);
        params.addProperty("pageSize", 10);
        JsonArray bizTypes = new JsonArray();
        if (type == 0) {
            bizTypes.add(201);
            bizTypes.add(202);
            bizTypes.add(203);
            bizTypes.add(204);
            bizTypes.add(205);
            bizTypes.add(206);
            bizTypes.add(207);
            bizTypes.add(208);
            bizTypes.add(209);
        } else if (type == 1) {
            bizTypes.add(101);
            bizTypes.add(102);
            bizTypes.add(103);
            bizTypes.add(104);
            bizTypes.add(105);
            bizTypes.add(106);
            bizTypes.add(107);
            bizTypes.add(108);
            bizTypes.add(109);
            bizTypes.add(1010);
            bizTypes.add(1011);
            bizTypes.add(1012);
            bizTypes.add(1013);
            bizTypes.add(1014);
            bizTypes.add(1015);
            bizTypes.add(1016);
        } else if (type == 2) {
            bizTypes.add(601);
            bizTypes.add(602);
        } else if (type == 3) {
            bizTypes.add(401);
            bizTypes.add(402);
            bizTypes.add(403);
            bizTypes.add(404);
        } else if (type == 4) {
            bizTypes.add(301);
            bizTypes.add(302);
            bizTypes.add(303);
            bizTypes.add(304);
            bizTypes.add(305);
            bizTypes.add(306);
            bizTypes.add(307);
            bizTypes.add(308);
            bizTypes.add(308);
            bizTypes.add(3010);
        } else if (type == 8) {
            bizTypes.add(501);
            bizTypes.add(502);
            bizTypes.add(503);
            bizTypes.add(504);
        }
        params.add("bizTypes", bizTypes);
        return params;
    }

    @NonNull
    private static JsonObject getAdminJsonObject(int page, int type) {
        JsonObject params = new JsonObject();
        params.addProperty("pageNo", page);
        params.addProperty("pageSize", 10);
        JsonArray bizTypes = new JsonArray();
        if (type == 0) {
            bizTypes.add(201);
            bizTypes.add(202);
            bizTypes.add(203);
            bizTypes.add(204);
            bizTypes.add(205);
        } else if (type == 1) {
            bizTypes.add(101);
            bizTypes.add(102);
            bizTypes.add(103);
            bizTypes.add(104);
            bizTypes.add(105);
            bizTypes.add(106);
            bizTypes.add(107);
            bizTypes.add(108);
            bizTypes.add(109);
            bizTypes.add(1010);
            bizTypes.add(1011);
        } else if (type == 2) {
            bizTypes.add(601);
            bizTypes.add(602);
        } else if (type == 3) {
            bizTypes.add(401);
            bizTypes.add(402);
        } else if (type == 4) {
            bizTypes.add(301);
            bizTypes.add(302);
            bizTypes.add(303);
            bizTypes.add(304);
            bizTypes.add(305);
            bizTypes.add(306);
        } else if (type == 8) {
            bizTypes.add(501);
            bizTypes.add(502);
        }
        params.add("bizTypes", bizTypes);
        return params;
    }

    public MutableResult<ResponseStatus<PointListBean>> getPointBeanResult() {
        return pointBeanResult;
    }


    /**
     * @param page
     */
    public void getUserRecord(int page,String keywords) {
        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                .getUserRecord(page, 10,keywords);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<UserDataBean>>() {
            @Override
            public void onSuccess(ResponseStatus<UserDataBean> dataResult) {

                userDataResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                userDataResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getPointDetail() {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getPointDetail();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<UserDataBean>>(new HttpOnNextListener<ResponseStatus<UserDataBean>>() {
            @Override
            public void onSuccess(ResponseStatus<UserDataBean> dataResult) {

                userResultProject.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                userResultProject.postValue(new ResponseStatus<>(1, true, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }
        });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getWelfarePoints() {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getWelfarePoints();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<Object>>() {
                    @Override
                    public void onSuccess(ResponseStatus<Object> dataResult) {

                        stringResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        stringResult.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getConsumptionPoints(int type) {
        Observable observable = null;
        if (type == 0) {
            observable = DataRepository.getRetrofitInstance().create(AccountService.class).getBonusPointsConfig();
        } else
            observable = DataRepository.getRetrofitInstance().create(AccountService.class).transferConsumptionFee();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<Object>>() {
                    @Override
                    public void onSuccess(ResponseStatus<Object> dataResult) {

                        stringResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        stringResult.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void welfarepoints(int type) {
        Observable observable = null;
        if (type == 0) {
            observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class).welfarepoints();
        } else
            observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class).consumption();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<Object>>() {
                    @Override
                    public void onSuccess(ResponseStatus<Object> dataResult) {

                        stringResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        stringResult.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getHTBTransferPointsConfig(int type) {
        Observable observable = null;
        if (type == 0) {
            observable = DataRepository.getRetrofitInstance().create(AccountService.class).getHTBTransferPointsConfig();
        } else
            observable = DataRepository.getRetrofitInstance().create(AccountService.class).getHTBTransferFee();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<Object>>() {
                    @Override
                    public void onSuccess(ResponseStatus<Object> dataResult) {

                        stringResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        stringResult.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void welfarePointsTransfer(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .welfarePointsUserTransfer(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }



    public void welfareBusinessPointsTransfer(int type, JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable;
        if (type == 0) {
            observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                    .welfarePointsTransfer(requestBody);
        } else
            observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                    .transferConsumption(requestBody);

        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getNotices() {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getNotices();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<MessageBean.DataBean>>>
                (new HttpOnNextListener<ResponseStatus<List<MessageBean.DataBean>>>() {
                    @Override
                    public void onSuccess(ResponseStatus<List<MessageBean.DataBean>> dataResult) {

                        messageListResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        messageListResult.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public MutableResult<ResponseStatus<List<MessageBean.DataBean>>> getMessageListResult() {
        return messageListResult;
    }

    public void redeemBonusPoints(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .redeemBonusPoints(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void transferConsumptionVolume(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .transferConsumptionVolume(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void addTenant(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .addTenant(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    /**
     * @param path
     */
    public void uploadFile(String path) {

        File file = new File(path);
        RequestBody requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
        MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), requestBody);

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .uploadFile(filePart);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<Object>>
                (new HttpOnNextListener<ResponseStatus<Object>>() {
                    @Override
                    public void onSuccess(ResponseStatus<Object> dataResult) {

                        stringResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        stringResult.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void getShopTypes() {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getShopTypes();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<LibraryInfo>>>
                (new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
                    @Override
                    public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                        libraryList.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        libraryList.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void queryServiceCenters() {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).queryServiceCenters();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<BusinessBean>>>
                (new HttpOnNextListener<ResponseStatus<List<BusinessBean>>>() {
                    @Override
                    public void onSuccess(ResponseStatus<List<BusinessBean>> dataResult) {

                        businessResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        businessResult.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getTenantTypes() {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getTenantTypes();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<BusinessSettleTypeBean>>>
                (new HttpOnNextListener<ResponseStatus<List<BusinessSettleTypeBean>>>() {
                    @Override
                    public void onSuccess(ResponseStatus<List<BusinessSettleTypeBean>> dataResult) {

                        businessSettleTypeResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        businessSettleTypeResult.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getBusinessSettleRecord() {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getBusinessSettleRecord();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<BusinessBean>>>
                (new HttpOnNextListener<ResponseStatus<List<BusinessBean>>>() {
                    @Override
                    public void onSuccess(ResponseStatus<List<BusinessBean>> dataResult) {

                        businessResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        businessResult.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getAgreement(String id) {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).getAgreement(id);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<LibraryInfo>>
                (new HttpOnNextListener<ResponseStatus<LibraryInfo>>() {
                    @Override
                    public void onSuccess(ResponseStatus<LibraryInfo> dataResult) {

                        libraryInfo.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        libraryInfo.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void invitedGift() {

        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class).invitedGift();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<LibraryInfo>>>
                (new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
                    @Override
                    public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                        libraryList.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        libraryList.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    /**
     * @param params
     */
    public void updateUser(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .updateUser(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void updateGoodsStatus(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                .updateGoodsStatus(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 核销订单
     *
     * @param params
     */
    public void verificationSheet(String id) {
        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                .verificationSheet(id);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * 确认收货
     *
     * @param id
     */
    public void receiveOrder(String id) {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .receiveOrder(id);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void updateLevelAndStar(String userId, String rank, String spid) {
        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                .updateLevelAndStar(userId, rank, spid);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }
    public void getRanks() {
        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                .getRanks();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<LibraryInfo>>>
                (new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
                    @Override
                    public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                        libraryList.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        libraryList.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void queryMccList() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .queryMccList();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<LibraryInfo>>>
                (new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
                    @Override
                    public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                        libraryList.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        libraryList.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }
    public void getDiamonds() {
        Observable observable = DataRepository.getRetrofitInstance().create(AccountService.class)
                .getDiamonds();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<List<LibraryInfo>>>
                (new HttpOnNextListener<ResponseStatus<List<LibraryInfo>>>() {
                    @Override
                    public void onSuccess(ResponseStatus<List<LibraryInfo>> dataResult) {

                        libraryList.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        libraryList.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }


    public void withdrawalApply(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                .withdrawalApply(requestBody);
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<String>>
                (new HttpOnNextListener<ResponseStatus<String>>() {
                    @Override
                    public void onSuccess(ResponseStatus<String> dataResult) {

                        srcSuccess.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        srcSuccess.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    public void getBusinessDetail() {

        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class).getBusinessDetail();
        BaseHttpObserver observer = new BaseHttpObserver<ResponseStatus<UserDataBean>>
                (new HttpOnNextListener<ResponseStatus<UserDataBean>>() {
                    @Override
                    public void onSuccess(ResponseStatus<UserDataBean> dataResult) {

                        userDataResult.postValue(dataResult);
                    }

                    @Override
                    public void onFail(String e) {
                        userDataResult.postValue(new ResponseStatus<>(1, true, e));

                    }

                    @Override
                    public void onComplete() {
                        mDisposable = null;
                    }
                });
        DataRepository.getInstance().subscribe(observable, observer);

    }

    /**
     * @param status
     */
    public void getTenantSpuList(int status) {
        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                .getTenantSpuList(status);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<ProductBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<ProductBean>> dataResult) {

                productBeanResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                productBeanResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }
    public void receiveTake(JsonObject params) {
        RequestBody requestBody = RequestBody.create(mediaType, params.toString());
        Observable observable = DataRepository.getAdminRetrofitInstance().create(AccountService.class)
                .receiveTake(requestBody);

        BaseHttpObserver observer
                = new BaseHttpObserver(new HttpOnNextListener<ResponseStatus<List<ProductBean>>>() {
            @Override
            public void onSuccess(ResponseStatus<List<ProductBean>> dataResult) {

                productBeanResult.postValue(dataResult);
            }

            @Override
            public void onFail(String e) {
                productBeanResult.postValue(new ResponseStatus<>(1, false, e));

            }

            @Override
            public void onComplete() {
                mDisposable = null;
            }

        });
        DataRepository.getInstance().subscribe(observable, observer);

    }
    public MutableResult<ResponseStatus<List<BusinessSettleTypeBean>>> getBusinessSettleTypeResult() {
        return businessSettleTypeResult;
    }
    //TODO tip 7：让 accountRequest 可观察页面生命周期，
    // 从而在页面即将退出、且登录请求由于网络延迟尚未完成时，
    // 及时通知数据层取消本次请求，以避免资源浪费和一系列不可预期问题。


    public void cancelLogin() {
        if (mDisposable != null && !mDisposable.isDisposed()) {
            mDisposable.dispose();
            mDisposable = null;
        }
    }

    @Override
    public void onStop(@NonNull @NotNull LifecycleOwner owner) {
        cancelLogin();
    }

    public MutableResult<ResponseStatus<UserDataBean>> getUserDataResult() {
        return userDataResult;
    }

    public MutableResult<ResponseStatus<String>> getSrcSuccess() {
        return srcSuccess;
    }

    public MutableResult<ResponseStatus<LibraryInfo>> getLibraryInfo() {
        return libraryInfo;
    }

    public MutableResult<ResponseStatus<List<LibraryInfo>>> getLibraryList() {
        return libraryList;
    }

    public MutableResult<ResponseStatus<List<LibraryInfo>>> getRainRecordList() {
        return rainRecordList;
    }

    public MutableResult<ResponseStatus<Object>> getStringResult() {
        return stringResult;
    }

    public MutableResult<ResponseStatus<List<ProductBean>>> getProductBeanResult() {
        return productBeanResult;
    }

    public MutableResult<ResponseStatus<ProductDetailBean>> getProductDetailResult() {
        return productDetailResult;
    }

    public MutableResult<ResponseStatus<ProductBean>> getProductResult() {
        return productResult;
    }

    public MutableResult<ResponseStatus<ProductBean>> getQueryDiscountedProductsResult() {
        return queryDiscountedProductsResult;
    }
}
